{% extends "base_generic.html" %}

{% block content %}
  <div class="detail-header">
    <h1><i class="fas fa-chart-line me-2"></i>图书排行榜</h1>
    <p class="lead">发现最受欢迎的图书</p>
  </div>
  
  <div class="row">
    <div class="col-md-4">
      <div class="detail-section">
        <h3><i class="fas fa-star me-2"></i>评分排行</h3>
        <div class="list-group">
          {% for book in top_rated %}
            <a href="{{ book.get_absolute_url }}" class="list-group-item list-group-item-action">
              <div class="d-flex w-100 justify-content-between">
                <h5 class="mb-1">{{ forloop.counter }}. {{ book.title }}</h5>
                <div class="rating">
                  {% with ''|center:book.avg_rating|floatformat:0|default:0 as range %}
                    {% for _ in range %}
                      <i class="fas fa-star"></i>
                    {% endfor %}
                  {% endwith %}
                  <small class="ms-1">{{ book.avg_rating|floatformat:1|default:"0.0" }}</small>
                </div>
              </div>
              <p class="mb-1">{{ book.author }}</p>
            </a>
          {% empty %}
            <div class="alert alert-info">暂无评分数据</div>
          {% endfor %}
        </div>
      </div>
    </div>
    
    <div class="col-md-4">
      <div class="detail-section">
        <h3><i class="fas fa-book-reader me-2"></i>借阅排行</h3>
        <div class="list-group">
          {% for book in most_borrowed %}
            <a href="{{ book.get_absolute_url }}" class="list-group-item list-group-item-action">
              <div class="d-flex w-100 justify-content-between">
                <h5 class="mb-1">{{ forloop.counter }}. {{ book.title }}</h5>
                <span class="badge bg-primary rounded-pill">{{ book.borrow_count|default:0 }}次</span>
              </div>
              <p class="mb-1">{{ book.author }}</p>
            </a>
          {% empty %}
            <div class="alert alert-info">暂无借阅数据</div>
          {% endfor %}
        </div>
      </div>
    </div>
    
    <div class="col-md-4">
      <div class="detail-section">
        <h3><i class="fas fa-heart me-2"></i>收藏排行</h3>
        <div class="list-group">
          {% for book in most_favorited %}
            <a href="{{ book.get_absolute_url }}" class="list-group-item list-group-item-action">
              <div class="d-flex w-100 justify-content-between">
                <h5 class="mb-1">{{ forloop.counter }}. {{ book.title }}</h5>
                <span class="badge bg-danger rounded-pill">{{ book.favorite_count|default:0 }}人</span>
              </div>
              <p class="mb-1">{{ book.author }}</p>
            </a>
          {% empty %}
            <div class="alert alert-info">暂无收藏数据</div>
          {% endfor %}
        </div>
      </div>
    </div>
  </div>
{% endblock %} 